package com.java.struts.base.action;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.java.struts.base.entity.GenericResult;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import com.opensymphony.xwork2.ActionSupport;

@ParentPackage(value="pkg")
@Namespace(value="/")
@Results(value = {
		@Result(name = "input",location = "/error.jsp"),
		@Result(name = "json",type = "json",params = {"root","result"}),
		@Result(name="listMenu",type="json",params = {"root","result"})
})
@Result(name="input",location="/error.jsp")
public abstract class BaseAction extends ActionSupport implements ServletResponseAware,ServletRequestAware{
	// 序列化
	private static final long serialVersionUID = 120265190522166185L;
	//创建对象
	protected HttpServletRequest request;
	protected HttpServletResponse response;
	protected GenericResult result;
	// 生成set  get方法
 	public GenericResult getResult() {
		return result;
	}

	public void setResult(GenericResult result) {
		this.result = result;
	}

	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}

	public void setServletResponse(HttpServletResponse response) {
		this.response = response;
	}
	
	public void setSession(String key,Object value) {
		HttpSession session = request.getSession();
		session.setAttribute(key, value);
	}
	
	public Object  getSession(String key) {
		HttpSession session = request.getSession();
		return session.getAttribute(key);
	}

	public void setSuccessResult(Object obj){
		result = new GenericResult();
		result.setSuccess(true);
		result.setData(obj);
	}
}
